package edu.flying.panda.taskmanager;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

public class MyListAdapter extends BaseAdapter {
	
	 private Activity activity;
	    private Task[] data;
	    private static LayoutInflater inflater=null;
	     
		/**
		 * Constructor method
		 */
	    public MyListAdapter(Activity a, Task[] d) {
	        activity = a;
	        if(d != null)
	        	data=d;
	        else
	        	data= new Task[1];
	        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);      
	    }

	    
		/**
		 * Getter method for the number of Tasks displayed on the Home Screen
		 * @return int Returns the number of Tasks as an Int
		 */
	    public int getCount() {
	        return data.length;
	    }

		/**
		 * Getter method for an Item (int position as param)
		 * @param position the position(Int) of the Item to be returned
		 * @return Returns an Object type
		 */
	    public Object getItem(int position) {
	        return position;
	    }

		/**
		 * Getter method for ItemID (int position as param)
		 * @param position The position(Int) of the Item to be returned
		 * @return Returns a Long type ItemID
		 */
	    public long getItemId(int position) {
	        return position;
	    }
	    
		/**
		 * Sets up the Task list (visually)
		 */
	    public View getView(int position, View convertView, ViewGroup parent) {
	        View vi=convertView;
	        if(convertView==null)
	            vi = inflater.inflate(R.layout.task_list_view, null);
	        Log.d("addTask","LA1");
	        TextView text=(TextView)vi.findViewById(R.id.label);
	        CheckBox cb=(CheckBox)vi.findViewById(R.id.completedCheckBox);
	        Log.d("addTask","LA2");
	        text.setTag((Integer)data[position].getId());
	        Log.d("addTask","LA3");
	        text.setText(data[position].getDescription());
	        cb.setChecked(data[position].isCompleted());
	        //cb.setClickable(false);
	        //vi.setClickable(true);
	        Log.d("addTask","LA4");
	        return vi;
	    }
}
